<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateAdminUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('admin_users', function (Blueprint $table) {
            $table->id();
            $table->string('username')->unique(); // 用户名
            $table->string('email')->unique(); // 邮箱
            $table->string('name'); // 姓名
            $table->string('phone')->nullable(); // 手机号
            $table->timestamp('email_verified_at')->nullable();
            $table->string('password'); // 密码
            $table->enum('role', ['super_admin', 'admin', 'operator'])->default('operator'); // 角色
            $table->enum('status', ['active', 'inactive', 'suspended'])->default('active'); // 状态
            $table->datetime('last_login_at')->nullable(); // 最后登录时间
            $table->string('last_login_ip')->nullable(); // 最后登录IP
            $table->rememberToken();
            $table->timestamps();
            
            // 索引
            $table->index(['username']);
            $table->index(['email']);
            $table->index(['role', 'status']);
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('admin_users');
    }
}